<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>divconsole.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_debug_divconsole.js.html">divconsole.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Simple logger that logs a Div Element.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.debug.DivConsole&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.debug.HtmlFormatter&#39;);
<a name="line23"></a>goog.require(&#39;goog.debug.LogManager&#39;);
<a name="line24"></a>goog.require(&#39;goog.style&#39;);
<a name="line25"></a>
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>/**
<a name="line29"></a> * A class for visualising logger calls in a div element.
<a name="line30"></a> * @param {Element} element The element to append to.
<a name="line31"></a> * @constructor
<a name="line32"></a> */
<a name="line33"></a>goog.debug.DivConsole = function(element) {
<a name="line34"></a>  this.publishHandler_ = goog.bind(this.addLogRecord, this);
<a name="line35"></a>  this.formatter_ = new goog.debug.HtmlFormatter();
<a name="line36"></a>  this.formatter_.showAbsoluteTime = false;
<a name="line37"></a>  this.isCapturing_ = false;
<a name="line38"></a>  this.element_ = element;
<a name="line39"></a>  this.elementOwnerDocument_ =
<a name="line40"></a>      this.element_.ownerDocument || this.element_.document;
<a name="line41"></a>
<a name="line42"></a>  this.installStyles();
<a name="line43"></a>};
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * Installs styles for the log messages and its div
<a name="line48"></a> */
<a name="line49"></a>goog.debug.DivConsole.prototype.installStyles = function() {
<a name="line50"></a>  goog.style.installStyles(
<a name="line51"></a>      &#39;.dbg-sev{color:#F00}&#39; +
<a name="line52"></a>      &#39;.dbg-w{color:#C40}&#39; +
<a name="line53"></a>      &#39;.dbg-sh{font-weight:bold;color:#000}&#39; +
<a name="line54"></a>      &#39;.dbg-i{color:#444}&#39; +
<a name="line55"></a>      &#39;.dbg-f{color:#999}&#39; +
<a name="line56"></a>      &#39;.dbg-ev{color:#0A0}&#39; +
<a name="line57"></a>      &#39;.dbg-m{color:#990}&#39; +
<a name="line58"></a>      &#39;.logmsg{border-bottom:1px solid #CCC;padding:2px}&#39; +
<a name="line59"></a>      &#39;.logsep{background-color: #8C8;}&#39; +
<a name="line60"></a>      &#39;.logdiv{border:1px solid #CCC;background-color:#FCFCFC;&#39; +
<a name="line61"></a>      &#39;font:medium monospace}&#39;,
<a name="line62"></a>      this.element_);
<a name="line63"></a>  this.element_.className += &#39; logdiv&#39;;
<a name="line64"></a>};
<a name="line65"></a>
<a name="line66"></a>
<a name="line67"></a>/**
<a name="line68"></a> * Sets whether we are currently capturing logger output.
<a name="line69"></a> * @param {boolean} capturing Whether to capture logger output.
<a name="line70"></a> */
<a name="line71"></a>goog.debug.DivConsole.prototype.setCapturing = function(capturing) {
<a name="line72"></a>  if (capturing == this.isCapturing_) {
<a name="line73"></a>    return;
<a name="line74"></a>  }
<a name="line75"></a>
<a name="line76"></a>  // attach or detach handler from the root logger
<a name="line77"></a>  var rootLogger = goog.debug.LogManager.getRoot();
<a name="line78"></a>  if (capturing) {
<a name="line79"></a>    rootLogger.addHandler(this.publishHandler_);
<a name="line80"></a>  } else {
<a name="line81"></a>    rootLogger.removeHandler(this.publishHandler_);
<a name="line82"></a>    this.logBuffer = &#39;&#39;;
<a name="line83"></a>  }
<a name="line84"></a>  this.isCapturing_ = capturing;
<a name="line85"></a>};
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * Adds a log record.
<a name="line90"></a> * @param {goog.debug.LogRecord} logRecord The log entry.
<a name="line91"></a> */
<a name="line92"></a>goog.debug.DivConsole.prototype.addLogRecord = function(logRecord) {
<a name="line93"></a>  var scroll = this.element_.scrollHeight - this.element_.scrollTop -
<a name="line94"></a>      this.element_.clientHeight &lt;= 100;
<a name="line95"></a>
<a name="line96"></a>  var div = this.elementOwnerDocument_.createElement(&#39;div&#39;);
<a name="line97"></a>  div.className = &#39;logmsg&#39;;
<a name="line98"></a>  div.innerHTML = this.formatter_.formatRecord(logRecord);
<a name="line99"></a>  this.element_.appendChild(div);
<a name="line100"></a>
<a name="line101"></a>  if (scroll) {
<a name="line102"></a>    this.element_.scrollTop = this.element_.scrollHeight;
<a name="line103"></a>  }
<a name="line104"></a>};
<a name="line105"></a>
<a name="line106"></a>
<a name="line107"></a>/**
<a name="line108"></a> * Gets the formatter for outputting to the console. The default formatter
<a name="line109"></a> * is an instance of goog.debug.HtmlFormatter
<a name="line110"></a> * @return {goog.debug.Formatter} The formatter in use.
<a name="line111"></a> */
<a name="line112"></a>goog.debug.DivConsole.prototype.getFormatter = function() {
<a name="line113"></a>  return this.formatter_;
<a name="line114"></a>};
<a name="line115"></a>
<a name="line116"></a>
<a name="line117"></a>/**
<a name="line118"></a> * Sets the formatter for outputting to the console.
<a name="line119"></a> * @param {goog.debug.Formatter} formatter The formatter to use.
<a name="line120"></a> */
<a name="line121"></a>goog.debug.DivConsole.prototype.setFormatter = function(formatter) {
<a name="line122"></a>  this.formatter_ = formatter;
<a name="line123"></a>};
<a name="line124"></a>
<a name="line125"></a>
<a name="line126"></a>/**
<a name="line127"></a> * Adds a separator to the debug window.
<a name="line128"></a> */
<a name="line129"></a>goog.debug.DivConsole.prototype.addSeparator = function() {
<a name="line130"></a>  var div = this.elementOwnerDocument_.createElement(&#39;div&#39;);
<a name="line131"></a>  div.className = &#39;logmsg logsep&#39;;
<a name="line132"></a>  this.element_.appendChild(div);
<a name="line133"></a>};
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Clears the console.
<a name="line138"></a> */
<a name="line139"></a>goog.debug.DivConsole.prototype.clear = function() {
<a name="line140"></a>  this.element_.innerHTML = &#39;&#39;;
<a name="line141"></a>};
</pre>


</body>
</html>
